package ledrpt

import org.kdx.DateUtils

import java.text.SimpleDateFormat

class ShipLotController {
    def dynamicQueryService
    def shipLot() {

        SimpleDateFormat sdf = new SimpleDateFormat('yyyy-MM-dd HH:mm:ss')
        def startTime = params.startTime ? sdf.parse(params.startTime) : sdf.parse(sdf.format(new Date().clearTime()))
        def endTime = params.endTime ? sdf.parse(params.endTime) : sdf.parse(sdf.format(new Date()))
        params.startTime = sdf.format(startTime)
        params.endTime = sdf.format(endTime)
        def dayList = DateUtils.getHourList(startTime, endTime)

        params.SYS_QUERY_NAME='packageForm'
        def packageForm=dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME='shipPartNameList'
        def shipPartNameList =dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'shipLot'
        def shipLot = dynamicQueryService.queryForList(params)

        [startTime:startTime,endTime:endTime,
         shipLot:shipLot,packageForm:packageForm,shipPartNameList:shipPartNameList,PART_NAME:params.PART_NAME,SUBSTRATE_ID1:params.SUBSTRATE_ID1,RESERVED1:params.RESERVED1,GRADE1:params.GRADE1
        ,MAIN_QTY:params.MAIN_QTY]
    }

    def exportExcel() {
        SimpleDateFormat sdf = new SimpleDateFormat('yyyy-MM-dd HH:mm:ss')
        def startTime = params.startTime ? sdf.parse(params.startTime) : sdf.parse(sdf.format(new Date().clearTime()))
        def endTime = params.endTime ? sdf.parse(params.endTime) : sdf.parse(sdf.format(new Date()))
        params.startTime = sdf.format(startTime)
        params.endTime = sdf.format(endTime)
        def dayList = DateUtils.getHourList(startTime, endTime)
        def sysQueryName
        sysQueryName = params.SYS_QUERY_NAME

        params.startNo = 1
        params.endNo = 99999999999999999
        params.startno = 1
        params.endno = 99999999999999999
        params.SYS_QUERY_NAME = sysQueryName

        params.SYS_QUERY_NAME = 'shipLot'
        def shipLot = dynamicQueryService.queryForList(params)
        params.SYS_QUERY_NAME = 'shipTotal'
        def shipTotal = dynamicQueryService.queryForList(params)
        String filename = new String("${sysQueryName}.xls".getBytes("UTF-8"), "UTF-8");
        response.setContentType('application/vnd.ms-excel;charset=UTF-8')
        response.setHeader('Content-disposition', "attachment;filename=${filename};charset=UTF-8")
        response.setCharacterEncoding("UTF-8");
        render(template: "export${params.EXPORT_CONTENT_NAME}", model: [

                shipTotal:shipTotal,
                shipLot: shipLot,shipLot:shipLot])
    }
}
